// pages/sousuo/sousuo.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    tabType: 'tab1',
    key: 'tab1',
    conditionList: [{
        title: '时间',
        id: '1',
        select: true
      },
      {
        title: '地点',
        id: '2',
        select: false
      },
      {
        title: '原因',
        id: '3',
        select: false
      },
      {
        title: '主要赔偿方',
        id: '4',
        select: false
      },
      {
        title: '医疗纠纷类型',
        id: '5',
        select: false
      },
    ],
    video: [],
    pic: [],
    operation: '',
    choosedCondition: {
      title: '时间',
      id: '1'
    },
    conditionVisible: false,
    length: -1,
    searchname: '',
  },

  showCondition() {
    this.setData({
      conditionVisible: !this.data.conditionVisible
    })
  },

  copyLink: function (e) {
    console.log(e.currentTarget.dataset.link)
    wx.setClipboardData({
      data: e.currentTarget.dataset.link,
      success: function (res) {
        wx.showToast({
          title: '复制成功，请在系统浏览器中粘贴并打开',
          icon: 'none'
        })
      }
    })
  },

  // 改变查询项
  onChnageCondition(e) {
    const list = this.data.conditionList
    list.forEach(item => {
      if (item.id === e.currentTarget.dataset.id) {
        item.select = true
        this.setData({
          'choosedCondition.title': item.title,
          'choosedCondition.id': item.id
        })
      } else {
        item.select = false
      }
    })
    this.setData({
      conditionList: list
    })
    console.log(list)
  },


  bindinputname: function (e) {
    console.log(e.detail.value)
    this.setData({
      searchname: e.detail.value
    })
  },

  bindSearch: function(e) {
    wx.showLoading({
      title: '加载中',
    })
    var that = this
    that.setData({
      examples: []
    })
    wx.cloud.callFunction({
      name:'searchExample',
      data: {
        keyWord:that.data.searchname,
        condition: that.data.choosedCondition
      }
    }).then(res => {
      wx.hideLoading()
      console.log(res.result.data)
      that.setData({
        examples: res.result.data
      })
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})